﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace ShopOnline.Controls
{
    public class WindowManager: Control
    {
        protected override void OnLoad(EventArgs e)
        {
            ScriptManager.RegisterClientScriptInclude(this, typeof(Page), Guid.NewGuid().ToString(), this.ResolveUrl("~/scripts/dhtmlwindow.js"));
            ScriptManager.RegisterClientScriptInclude(this, typeof(Page), Guid.NewGuid().ToString(), this.ResolveUrl("~/scripts/modal.js"));
            string script = string.Format("dhtmlwindow.imagefiles = ['{0}', '{1}', '{2}', '{3}'];", 
                this.ResolveUrl("~/images/windowfiles/min.gif"),
                this.ResolveUrl("~/images/windowfiles/close.gif"),
                this.ResolveUrl("~/images/windowfiles/restore.gif"),
                this.ResolveUrl("~/images/windowfiles/resize.gif")) +
            "var windowManager = { \r\n" +
                "currentWindow: null,\r\n" +
                "returnValue: null,\r\n" +
                "closeWindow: function (rs) {\r\n" +
                    "parent.windowManager.returnValue = rs;\r\n" +
                    "parent.windowManager.currentWindow.hide();\r\n" +
                "}\r\n" +
            "}\r\n";
            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), Guid.NewGuid().ToString(), script, true); 
        }
    }
}